package com.common.app.data.bean

import android.graphics.drawable.Drawable
import android.os.Parcelable
import com.common.app.R
import com.common.base.app.extras.dp2px
import com.common.base.utils.AppUtils.getString
import com.contrarywind.interfaces.IPickerViewData
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import java.util.Calendar
import kotlin.collections.ArrayList


/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/8/19
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
/***首页**/
const val FRAGMENT_ID_HOME = 0

/***睡眠**/
const val FRAGMENT_ID_SLEEP = 1

/***健身**/
const val FRAGMENT_ID_FITNESS = 2

/***我**/
const val FRAGMENT_ID_ME = 3

data class ReportBean(
    val event_value: String,
    val duration: Long,  //s为单位
    val starttime: Long, //s为单位
    val endtime: Long, //s为单位
    val userId: String, //用户id 未登录时为设备id
)


class PayBean {
    var wxPayData: WXPayBean? = null
    var aliPayData: String = ""
    var payType: PayType = PayType.WECHAT
}

enum class PayType {
    WECHAT,
    ALIPAY
}

class WXPayBean {
    @JvmField
    @SerializedName("package")
    var paysign: String = ""
    var appid: String = ""
    var sign: String = ""
    var partnerid: String = ""
    var prepayid: String = ""
    var noncestr: String = ""
    var timestamp: String = ""
}

data class PayResult(
    var payType: PayType = PayType.WECHAT,
    var payStatus: PayStatus = PayStatus.SUCCESS
)

enum class PayStatus {
    CANCEL,
    SUCCESS,
    FAILED
}

fun getSelectedIndex(index: Int): Int {
    return when (index) {
        1 -> FRAGMENT_ID_SLEEP
        2 -> FRAGMENT_ID_FITNESS
        3 -> FRAGMENT_ID_ME
        else -> FRAGMENT_ID_HOME
    }
}

class DialogButBean(
    var txt: String = "",
    var color: Int = R.color.color_3a3a3a,
    var bgColor: Int = R.color.white,
    var cornerBL: Int = dp2px(8),
    var cornerBR: Int = dp2px(8),
    var cornerTL: Int = 0,
    var cornerTR: Int = 0,
)

data class TimeSelectorModel(
    var dataList: ArrayList<TimeSelectorBean> = ArrayList(),
)

@Parcelize
data class CityRegionModel(

    /**
     *
     */
    var children: MutableList<CityRegionModel>,

    var code: String = "",
    var name: String = "",

    /**
     * cityInitials
     */
    var initials: String = "",

    ) : Parcelable

data class AppConfigBean(
    val publicSacrifice: Int,//公祭日开关
    val Path: String? = null
)

@Parcelize
data class InviteCodeModel(
    val regUrl: String? = "",
    val inviteCode: String? = "",
) : Parcelable

@Parcelize
data class CityCommonModel(

    /**
     *
     */
    var alpha: String? = null,
    /**
     *
     */
    val name: String? = null,

    ) : Parcelable

data class FloatWindowConfig(
    val position: Int, // 展示位置 1:直播首页 2:直播间
    var logoUrl: String, //图片url
    val linkUrl: String, //链接
    val gifFromAssets: Drawable? = null
)

@Parcelize
data class AdInfoBean(
    var Id: Long,//广告Id
    var Title: String,//广告标题
    var JumpType: String,//跳转类型
    var JumpData: String,//跳转具体类型
    var ImgUrl: String,//广告图片Url
    var Content: String,//广告内容
    var ButtonContent: String,//广告按钮
    var Status: Int,//1-上架，2-下架，3-初始状态
    var StartTime: String?,//生效开始时间
    var EndTime: String?,//生效结束时间
    var IsShowLabel: Int?,//1-是；2-否 展示开屏广告的广告标签
    var AdType: Int,//1-弹窗广告，2-分类页banner广告，3-开屏广告
    var AppShowTactics: Int,//app展示策略，1-每天展示一次，2-每次打开APP时展示
) : Parcelable {
    @Volatile
    var prepared = false//图片下载完成
    fun hideAdLabel(): Boolean {
        return IsShowLabel != 1
    }
}

@Parcelize
data class WebInteractDataModel(
    var androidAppUrl: String? = "", //跳转安卓链接地址
    var androidDownloadUrl: String? = "", // 安卓下载链接
    var androidPackage: String? = "", // 安卓包名
    var title: String? = "", // 应用名
    var text: String? = "", // 文本内容
    var urlType: Int = -1, // 链接类型(0:内部跳转 1.app跳转 2:h5跳转3打开新web页面4或鉴权CODDE)
    var urlLink: String? = "", // h5或内部链接地址

) : Parcelable

@Parcelize
data class SysListDataModel(
    var addTime: Long = 0,//添加时间
    var content: String? = "",//内容
    var contentId: String? = "",//
    var publishe: String? = "",//发布人
    var themeType: Int, // 主题类型 1-发现、2-商城、3-念念、4-乐十
    var title: String? = "",//标题
    var expireTime: Long = 0,//倒计时
    var readStatus: Boolean = false,
) : Parcelable

@Parcelize
data class CommonMessageRelayModel(
    val skipPath: String? = "",
    val webType: Int = 0,
    var parametersMap: HashMap<String, String>? = null,
) : Parcelable

data class VersionResBean(
    var forced: Int = 0,        // 更新类型 1非强更 2强更
    val apkUrl: String = "",
    val descr: String = "",
    val downloadUrl: String = "",
    val versionName: String? = "",
    val versionCode: Int = 0
)

data class ToolsBean(val icon: Int, val name: String)

@Parcelize
data class ShareInfo (
    var title: String? = null,
    var description: String? = null,
    var thumbUrl: String? = null,
    var webPageUrl: String? = null,
    var miniProgramPath: String? = null,
    var wxAppId: String? = null,
    var miniProgramId: String? = null,
): Parcelable

@Parcelize
data class UpSignDataModel(
    var activity_subtype: String? = "",
    var activity_type: String? = "",
    var data: String? = "",
    var data_source: String? = "",
    var data_type: String? = "",
    var firmware_version: String? = "",
    var mac_address: String? = "",
    var manufacturer_id: String? = "",
    var physiological_status: String? = "",
    var software_version: String? = "",
    var system_type: String? = "",
    var system_version: String? = "",
    var timezone: String? = "",
    var timestamp: String? = "",
    var nonce: String? = "",
) : Parcelable

@Parcelize
data class UpKvDataModel(
    var timestamp: String? = "",
    var value: String? = "",
) : Parcelable

@Parcelize
data class ServerSseDataModel(
    val progress: Int = 0,//进度
    val data: List<CloudDownDataModel>? = null,//数据体
    val data_count: Long = 0,//
): Parcelable

@Parcelize
data class ServerHealthTypeDataModel(
    val type: String? = null,//数据类型
    val value: String? = null,//压缩数据
): Parcelable

@Parcelize
data class SSEEvent(
    val type: String = "message",
    val data: String,
    val id: String? = null,
    val retry: Long? = null
): Parcelable

/**
 * 日历日期数据模型
 */
data class CalendarDay(
    val year: Int,
    val month: Int,
    val day: Int,
    val isCurrentMonth: Boolean = true,
    val isToday: Boolean = false,
    var isSelected: Boolean = false,
    val hasEvent: Boolean = false,
    val dateName: String = "",
    val mCalendar: Calendar?=null
) : IPickerViewData {
    fun toCalendar(): Calendar {
        return Calendar.getInstance().apply {
            set(year, month, day)
        }
    }

    fun getDateString(): String {
        return String.format("%04d-%02d-%02d", year, month + 1, day)
    }

    override fun getPickerViewText(): String {
        return  dateName
    }
}

/**
 * 日历月份数据模型
 */
data class CalendarMonth(
    val year: Int,
    val month: Int,
    val days: List<CalendarDay>
) {
    companion object {
        fun create(year: Int, month: Int): CalendarMonth {
            val calendar = Calendar.getInstance()
            calendar.set(year, month, 1)

            val daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH)
            // 修正：将周日作为一周的最后一天，周一作为第一天
            val dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
            val firstDayOfWeek = if (dayOfWeek == Calendar.SUNDAY) 6 else dayOfWeek - 2

            val days = mutableListOf<CalendarDay>()

            // 添加上个月的日期填充（只占位，不显示）
            val prevMonth = if (month == 0) 11 else month - 1
            val prevYear = if (month == 0) year - 1 else year
            calendar.set(prevYear, prevMonth, 1)
            val daysInPrevMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

            for (i in firstDayOfWeek - 1 downTo 0) {
                days.add(
                    CalendarDay(
                        prevYear,
                        prevMonth,
                        daysInPrevMonth - i,
                        isCurrentMonth = false
                    )
                )
            }

            // 添加当前月的日期
            val today = Calendar.getInstance()
            for (day in 1..daysInMonth) {
                val isToday = today.get(Calendar.YEAR) == year &&
                        today.get(Calendar.MONTH) == month &&
                        today.get(Calendar.DAY_OF_MONTH) == day

                days.add(
                    CalendarDay(
                        year,
                        month,
                        day,
                        isCurrentMonth = true,
                        isToday = isToday
                    )
                )
            }

            // 添加下个月的日期填充（只占位，不显示）
            val nextMonth = if (month == 11) 0 else month + 1
            val nextYear = if (month == 11) year + 1 else year
            val remainingDays = 42 - days.size // 6行 * 7列

            for (day in 1..remainingDays) {
                days.add(
                    CalendarDay(
                        nextYear,
                        nextMonth,
                        day,
                        isCurrentMonth = false
                    )
                )
            }

            return CalendarMonth(year, month, days)
        }
    }
}

@Parcelize
data class WcCityBean(
    val areaName: String = "",
    val areaList: List<WcCityBean>?=null,
    val bankAreaId: String = "",
) : IPickerViewData,Parcelable {
    override fun getPickerViewText(): String {
        return  if (areaName.isNullOrEmpty()) getString(R.string.common_not_select_hint)  else areaName
    }
}

@Parcelize
data class WcAllCityModel(
    val data: List<WcCityBean>?=null,
): Parcelable


@Parcelize
data class UpFileModel(
    val url: String = "",
    val id: Long = 0,
    val type: String = "",
) : Parcelable {}

@Parcelize
data class TimeComponents(
    val days: Long,
    val hours: Long,
    val minutes: Long,
    val seconds: Long,
    val milliseconds: Long
) : Parcelable {}
@Parcelize
data class CommonMeasureResultModel(
    val measureType: Int = -2,
    var value: Number = 0,
) : Parcelable

@Parcelize
class IntelligentTouchOptionModel(
    var id: Int,
    val name: String? = "",
    val hint: String? = "",
    var isSelect: Boolean = false,
) : Parcelable